<template>
  <el-dialog title="Invite Member" :visible.sync="dialogVisible" width="30%">
    <div>
      <el-alert :closable="false" title="Please fill in the invitee’s Office 365 email address so that the invitee can sign up or sign in to MSPbots and join the group more easily." type="info">
      </el-alert>
      <el-form :model="form" class="demo-form-inline">
        <el-form-item label="Email">
          <el-input type="textarea" resize="none" v-model="form.email" placeholder="Separate emails with commas. Example: email@example.com, email2@example.com."></el-input>
        </el-form-item>
        <el-form-item label="Description">
          <el-input type="textarea" resize="none" v-model="form.desc" placeholder="Please enter a description for your invitation"></el-input>
        </el-form-item>
      </el-form>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" size="small" @click="inviteUser" v-loading="loading">Send Email</el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {
  name: 'memberInvite',
  props: ['visible'],
  data () {
    return {
      loading: false,
      form: {
        email: '',
        desc: ''
      }
    }
  },
  computed: {
    dialogVisible: {
      get () {
        return this.visible
      },
      set (val) {
        this.$emit('update:visible', val)
      }
    }
  },
  methods: {
    async inviteUser () {
      this.loading = true
      const params = {
        groupId: this.$route.query.groupId,
        emails: this.form.email,
        description: this.form.desc
      }
      const { invitePeerGroupUser } = this.$interface.system
      const { data } = await invitePeerGroupUser(params)
      if (data.code === 0) {
        this.$message.success(data.msg)
      } else {
        this.$message.error(data.msg)
      }
      this.loading = false
      this.dialogVisible = false
    }
  }
}
</script>

<style scoped>

</style>
